<?php 
namespace app\common\model;
class IPAttribution {
    
    /**
     * 通过IP定位经纬度
     * @param string $ip [ip 地址]
     */
    public function IPAttributionQuery($ip = '') {
        $res = file_get_contents('http://api.map.baidu.com/highacciploc/v1?qcip='.$ip.'&qterm=pc&ak=BFee47d04a96d8448e2e24e451a5cbb3&callback_type=json&extensions=1&coord=bd09ll');
        $res = json_decode($res, true);
        return array(
            'lat' => $res['content']['location']['lat'], //维度
            'lng' => $res['content']['location']['lng'], //经度
            'address' => $res['content']['formatted_address']
        );
    }
}
?>